#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, k;
int w[N];
vector<int> ch[N];
int f[N][25];
void dfs(int u, int fu) {
  rep(i, 0, k) f[u][i] = w[u];
  for (int v : ch[u]) {
    if (v == fu) continue;
    dfs(v, u);
    rep(i, 1, k) f[u][i] += f[v][i - 1];
  }
}
int dp[N][25];
void dfs2(int u, int fu) {
  if (u == fu) {
    rep(i, 0, k) dp[u][i] = f[u][i];
  } else {
    dp[u][0] = w[u];
    rep(i, 1, k) dp[u][i] = dp[fu][i - 1] + f[u][i] - f[u][i - 2];
  }
  for (int v : ch[u]) {
    if (v == fu) continue;
    dfs2(v, u);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    ch[u].push_back(v);
    ch[v].push_back(u);
  }
  rep(i, 1, n) cin >> w[i];
  dfs(1, 1);
  dfs2(1, 1);
  rep(i, 1, n) cout << dp[i][k] << endl;
  return 0;
}